
jQuery(document).ready(function() {
	var complainId = getUrlParam('complainId');
	$('#complainId').val(complainId);
	initForm(complainId);
	
})

function initForm(complainId){

	var infoUrl = projectPath + "consulting/list.do";
	
	$.ajax({ 
		url: infoUrl,
		method: 'post',
		data:JSON.stringify({"complainId": complainId}),
		dataType: "json",
		contentType: "application/json",
		success: function(data){ 
			bindFormConsultingInfo(data.rows[0]);
      	}
	});
}

function bindFormConsultingInfo(data){
	$('#userName').html(data.userName);
	$('#mobile').html(data.mobile);
	$('#email').html(data.email);
	$('#businessType').html(data.businessTypeName);
	$('#complainType').html(data.complainType);
	$('#complainTitle').html(data.complainTitle);
	$('#leaveMessage').html(data.leaveMessage);
	$('#orgCode').html(data.orgCode);
	$('#orgName').html(data.orgName);
	
	if(data.complainStatus == "1"){
		$("#tbody").append(
			'<tr><td class="tdTitle">回复内容：</td><td colspan="3">'+
			'<span id="replyMessage">'+data.replyMessage+'</span>'+
			'</td></tr>'+
			'<tr><td class="tdTitle">回复部门：</td><td colspan="3">'+
			'<span id="sysdeptname" name="sysdeptname">'+data.sysdeptname+'</span>'+
			'<tr><td class="tdTitle">回复人：</td><td>'+
			'<span id="syscreatedbyname" name="syscreatedbyname">'+data.syscreatedbyname+'</span>'+
			'<td class="tdTitle">回复时间：</td><td>'+
			'<span id="replyTime" name="replyTime">'+data.replyTime+'</span>'+
			'</td></tr>'
		);
	}else{
		$("#tbody").append(
			'<tr><td>回复内容：</td><td colspan="3">'+
			'<textarea id="replyMessage" class="form-control" rows="5" placeholder="请输入回复内容" name="replyMessage">'+
			'</textarea></td></tr>'
		);
	}
	
}

function save(){
	var consultingData = $("#consultingForm").serializeObject();
	if(!check(consultingData)){
		return true;
	}
	
	$.ajax({ 
		method: 'post',
		url: basePath() + 'consulting/update.do',
		data: JSON.stringify(consultingData),
		dataType: "json",
        contentType: "application/json",
		success: function(data){
			window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success,{
				onOk: function(){
					if(data.result == 1){
						parent.refreshData();//刷新数据
					} 
				}
			});
      	}
		
	});
	
}

function check(data){	
var result = true;

	
	var strMsg = "";
	var obj = $('#replyMessage');
	if(obj.val() == ""){
		strMsg += obj.attr("placeholder") + "！<br />";
		
		result = false;
	}

	if(strMsg != ""){
		window.wxc.xcConfirm(strMsg, window.wxc.xcConfirm.typeEnum.error);
	}
	
	return result;
}

